from django.db import models
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _

class IP(models.Model):
    ip = models.IPAddressField(unique=True)

    @property
    def is_selected(self):
        return Profile.objects.filter(ip=self).count() > 0

    def __unicode__(self):
        return "%s%s" % (self.ip, " - used" if self.is_selected else ' - free')

class Plan(models.Model):
    name = models.CharField(max_length=255)
    sites_max = models.IntegerField()
    databases_max = models.IntegerField()
    quota_max = models.IntegerField()

    def __unicode__(self):
        return self.name

class Profile(models.Model):
    user = models.ForeignKey(User, unique=True)
    plan = models.ForeignKey(Plan)
    ip = models.ForeignKey(IP)
    status = models.IntegerField()
    sites_used = models.IntegerField()
    databases_used = models.IntegerField()
    quota_used = models.IntegerField()

    def __unicode__(self):
        return self.user.username
